#ifndef INTERRUPTHANDLER_H
#define INTERRUPTHANDLER_H
#include <arduino.h>
class Callback
{
  public:
  virtual void callbackFunc()=0;
};

class InterruptHandlerInterface
{
  public:
    virtual void onInterrupt()=0;
};

InterruptHandlerInterface* IntHandlers[2];
void int0Func()
{
  IntHandlers[0]->onInterrupt();
}
void int1Func()
{
  IntHandlers[1]->onInterrupt();
}

void(*intHandlerFunctions[])() = {int0Func, int1Func};
void RegisterForInterrupt(unsigned int interruptNumber, InterruptHandlerInterface* handlerObject)
{
    IntHandlers[interruptNumber] = handlerObject;
    attachInterrupt(interruptNumber, intHandlerFunctions[interruptNumber], CHANGE);         // configure interrupt for the BMA on rising edge

}
void DeregisterFromInterrupt(unsigned int interruptNumber)
{
    detachInterrupt(interruptNumber);
}
class InterruptHandler :public InterruptHandlerInterface
{
  public:
  InterruptHandler(short encoderPin)
    :_encoderPin(encoderPin)
    {
        pinMode(encoderPin, INPUT);
        RegisterForInterrupt(encoderPin-2,this);
    }
    virtual ~InterruptHandler()
    {
        DeregisterFromInterrupt(_encoderPin-2);
    }

    virtual void onInterrupt()=0;
private:
    short _encoderPin;

};

#endif // INTERRUPTHANDLER_H
